<template>
  <div class="app-container">
    <div class="page_head">
      <div class="button_bar">
        <el-button type="primary" @click="refresh()">刷新</el-button>
      </div>
      <div class="button_bar">
        <el-button v-permission="'course:save'" type="primary" @click="toCourseAdd()">添加班级</el-button>
      </div>
      <div>
        <el-dialog :title="title" :model-value="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="班级名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入班级名称" />
            </el-form-item>
            <el-form-item label="班级详情" prop="classDesc">
              <el-input v-model="form.classDesc" placeholder="请输入班级详情" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </div>

    </div>
    <el-table :data="list" row-key="id" class="drag-table">
      <el-table-column :min-width="60" label="班级名称" prop="name">
      </el-table-column>
      <el-table-column :min-width="60" label="班级邀请码" prop="inviteId">

      </el-table-column>
      <el-table-column :min-width="30" label="详情" prop="classDesc">

      </el-table-column>
    </el-table>

  </div>
</template>

<script>

  import { ref } from 'vue'
  import { courseApi } from '@/api/course'
  import {} from 'element-plus'


  export default {
    data() {
      return {
        list: [],
        form: {},
        open: false,
        title: '班级'
      }
    },
    mounted() {
      this.refresh()
    },
    methods: {
      refresh() {
        let _this = this
        courseApi.listClass().then(res=>{
          console.log("aaaaaaaaaaaaaaaaaaaaaaaaa")
          _this.list = res
          console.log(res.data)
        })
      },
      addClass() {
        courseApi.createClass(this.form)
      },
      toCourseAdd() {
        console.log('babababbababab')
        this.open = true
      },
      submitForm() {
        this.addClass()
        this.open = false
      },
      cancel() {
        this.open = false
      }

    }
  }


</script>
